<%@ page language="java" contentType="text/html; charset=UTF8" pageEncoding="UTF8"%>
<%@ page import="java.util.*" %>
<%@ page import="bcnet.service.PriceHistoryService" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%
	PriceHistoryService priceHistoryService = new PriceHistoryService();
	List<String> codeList = priceHistoryService.getCodeList();
	
	Calendar cal = Calendar.getInstance();
	// No need to get back yesterday because HK is GMT+8
	//cal.add(Calendar.DATE, -1);
	
	Date todayDate = cal.getTime();
	SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
	SimpleDateFormat sdfMonth = new SimpleDateFormat("MM");
	SimpleDateFormat sdfDate = new SimpleDateFormat("dd");
	
	String fromYear = sdfYear.format(todayDate);
	int fromMonthInt = Integer.parseInt(sdfMonth.format(todayDate));
	fromMonthInt--;
	String fromMonth = String.format("%02d", fromMonthInt);	
	String fromDate = sdfDate.format(todayDate);
	String toYear = sdfYear.format(todayDate);
	int toMonthInt = Integer.parseInt(sdfMonth.format(todayDate));
	toMonthInt--;
	String toMonth = String.format("%02d", toMonthInt);	
	String toDate = sdfDate.format(todayDate);

	for(int i=0; i<codeList.size(); i++){
		//System.out.println(codeList.get(i));
		//System.out.println(fromYear +","+  fromMonth+","+  fromDate+","+  toYear+","+  toMonth+","+  toDate);
		priceHistoryService.addPriceHistoryMass(codeList.get(i),  fromYear,  fromMonth,  fromDate,  toYear,  toMonth,  toDate);
	}
	out.println(todayDate);
%>

